"""
@Author  : 康帅
@Time    : 2021/6/9 14:22
@Function: 中文拼音转成简拼及全拼
"""
# pip3 install xpinyin


from xpinyin import Pinyin


def pinyin():
    """
    中文拼音转成简拼及全拼
    :return:
    """
    p = Pinyin()
    print(p.get_pinyin("上海"))  # shang-hai
    print(p.get_pinyin("上海", tone_marks='marks'))  # shàng-hǎi
    print(p.get_pinyin("上海", tone_marks='numbers'))  # shang4-hai3
    print(p.get_pinyin("上海", ''))  # shanghai
    print(p.get_pinyin("上海", ' '))  # shang hai
    print(p.get_initial("上"))  # S
    print(p.get_initials("上海"))  # S-H
    print(p.get_initials("上海", ''))  # SH
    print(p.get_initials("上海", ' '))  # S H
    print(p.get_initials("上海", splitter='-', with_retroflex=True))  # SH-H
    print(p.get_pinyins('模型', splitter=' ', tone_marks='marks'))  # ['mó xíng', 'mú xíng']
    # ['mó yáng', 'mó yàng', 'mó xiàng', 'mú yáng', 'mú yàng', 'mú xiàng']
    print(p.get_pinyins('模样', splitter=' ', tone_marks='marks'))


if __name__ == '__main__':
    pinyin()
